package mafiagame.roles;

import java.util.ArrayList;
import java.util.List;

import mafiagame.Action;
import mafiagame.Game;
import mafiagame.Mark;
import mafiagame.RoleDefinition;
import mafiagame.Mark.MarkScope;
import mafiagame.Mark.MarkType;
import mafiagame.RoleDefinition.DefinitionType;
import mafiagame.roles.Detective.DetectiveRole;
import mafiagame.Player;
import mafiagame.Role;

public class Vigilante extends RoleDefinition
{
	public DefinitionType getDefinitionType()
	{
		return DefinitionType.KILLING;
	}

	public String explainRole()
	{
		return "You are the vigilante. You can kill someone once per game!";
	}

	public Vigilante()
	{
		super();
	}

	public void assignRole(Game g, Player p)
	{
		p.roles.add(new VigilanteRole(g, p));
	}
	public String getName()
	{
		return "VIGILANTE";
	}
	public static class VigilanteRole extends Role
	{
		public class KillAction extends Action
		{
			@Override
			public String getDescription()
			{
				return "This will allow you to <b>kill</b> a player for this night phase. Note that you can only use"
						+ " this power once a game!";
			}

			@Override
			public String getCommand()
			{
				return "murder";
			}

			@Override
			public boolean Execute(String message)
			{
				if (alreadyKilled)
				{
					myGame.communicator.sendPrivateMessage(myPlayer.username,
							"You may only murder one person per game!");
					return false;
				}

				String[] tokens = message.split(" ");
				if (tokens.length != 2)
				{
					myGame.communicator
							.sendPrivateMessage(
									myPlayer.username,
									"The kill must be of the format 'murder [number]' where the number is the player number you wish to heal.");
					return false;
				}
				Player p = myGame.parsePlayer(tokens[1]);
				if (p == null)
				{
					myGame.communicator
							.sendPrivateMessage(myPlayer.username,
									"You must choose a player who is actually playing.");
					return false;
				}
				if (!p.living)
				{
					myGame.communicator.sendPrivateMessage(myPlayer.username,
							"You must choose a player who is alive to kill.");
					return false;
				}

				Mark m = new Mark();
				m.type = MarkType.KILL;
				m.duration = 1;
				m.scope = MarkScope.NIGHT;
				m.isBlockable = true;
				m.isRedirectable = true;
				m.source = myPlayer;
				p.marks.add(m);

				alreadyKilled = true;

				myGame.communicator.sendPrivateMessage(myPlayer.username,
						"Murdering <b>" + p.username + "</b> tonight!");

				return true;
			}

			@Override
			public boolean isPublic()
			{
				return false;
			}

		}

		private boolean alreadyKilled;

		public VigilanteRole(Game g, Player p)
		{
			super(g, p);

			alreadyKilled = false;
		}

		public String getName()
		{
			return "VIGILANTE";
		}

		public String getHelp()
		{
			return "You are the vigilante. You can kill someone once per game!";
		}

		@Override
		public void SetupPhase()
		{

		}

		@Override
		public void NightPhase()
		{
			if (!alreadyKilled)
				myGame.addAction(myPlayer.username,
						new KillAction(), false);
		}

		@Override
		public void DayPhase()
		{

		}
	}
}
